home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Chainsaw Launcher.lua < prev    next >
Text File  |  2010-09-22  |  7KB  |  185 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Chainsaw Launcher + Projectile Chainsaw
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.chainsawlauncher={}
  10. cc.chainsawlauncher.chainsaw={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.chainsawlauncher.gfx_wpn=loadgfx("weapons/launcher.bmp")                        -- Weapon Image
  14. setmidhandle(cc.chainsawlauncher.gfx_wpn)
  15. cc.chainsawlauncher.gfx_pro0=loadgfx("weapons/chainsaw0.bmp")                    -- Projectile Image
  16. setmidhandle(cc.chainsawlauncher.gfx_pro0)
  17. cc.chainsawlauncher.gfx_pro1=loadgfx("weapons/chainsaw1.bmp")                    -- Projectile Image
  18. setmidhandle(cc.chainsawlauncher.gfx_pro1)
  19. cc.chainsawlauncher.sfx_attack=loadsfx("chainsawlaunch.wav")                    -- Attack Sound
  20. cc.chainsawlauncher.sfx_cut=loadsfx("sawcut.ogg")                                -- Cut Sound
  21.  
  22. --------------------------------------------------------------------------------
  23. -- Weapon: Chainsaw Launcher
  24. --------------------------------------------------------------------------------
  25.  
  26. cc.chainsawlauncher.id=addweapon("cc.chainsawlauncher","Chainsaw Launcher",cc.chainsawlauncher.gfx_pro0,0,2)    -- Add Weapon (0 uses, first in round 2)
  27. cc.chainsawlauncher.ammo=3                                                        -- 3 Shots
  28.  
  29. function cc.chainsawlauncher.draw()                                                -- Draw
  30.     setblend(blend_alpha)
  31.     setalpha(1)
  32.     setcolor(255,90,100)
  33.     drawinhand(cc.chainsawlauncher.gfx_wpn,6,0)
  34.     -- HUD ammobar
  35.     if cc.chainsawlauncher.ammo-weapon_shots>0 then
  36.         hudammobar(cc.chainsawlauncher.ammo-weapon_shots,cc.chainsawlauncher.ammo)
  37.     end
  38.     -- HUD Crosshair
  39.     if cc.chainsawlauncher.ammo-weapon_shots>0 then
  40.         hudcrosshair(6,3)
  41.     end
  42. end
  43.  
  44. function cc.chainsawlauncher.attack(attack)                                        -- Attack
  45.     -- Decrement timer
  46.     if weapon_timer>0 then
  47.         weapon_timer=weapon_timer-1
  48.     end
  49.     -- Attack
  50.     if weapon_shots<cc.chainsawlauncher.ammo and weapon_timer<=0 and attack==1 then
  51.         -- No more weapon switching!
  52.         useweapon(0)
  53.         weapon_timer=25
  54.         playsound(cc.chainsawlauncher.sfx_attack)
  55.         weapon_shots=weapon_shots+1
  56.         id=createprojectile(cc.chainsawlauncher.chainsaw.id)
  57.         projectiles[id]={}
  58.         -- Ignore collision with current player at beginning
  59.         projectiles[id].ignore=playercurrent()
  60.         -- Set initial position of projectile
  61.         projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
  62.         projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
  63.         -- Animation
  64.         projectiles[id].frame=0
  65.         projectiles[id].frametimer=0
  66.         -- Timer
  67.         projectiles[id].timer=0
  68.         -- Initial movement
  69.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
  70.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
  71.         projectiles[id].x=projectiles[id].x-projectiles[id].sx
  72.         projectiles[id].y=projectiles[id].y-projectiles[id].sy
  73.         cc.chainsawlauncher.chainsaw.move(id,0)
  74.         -- Set speed of projectile
  75.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*7.0
  76.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*7.0
  77.         -- Effects
  78.         recoil(5)
  79.         -- End Turn
  80.         if (weapon_shots>=cc.chainsawlauncher.ammo) then
  81.             endturn()
  82.         end
  83.     end
  84. end
  85.  
  86. --------------------------------------------------------------------------------
  87. -- Projectile: Chainsaw
  88. --------------------------------------------------------------------------------
  89.  
  90. cc.chainsawlauncher.chainsaw.id=addprojectile("cc.chainsawlauncher.chainsaw")        -- Add Projectile
  91.  
  92. function cc.chainsawlauncher.chainsaw.draw(id)                                        -- Draw
  93.     -- Setup draw mode
  94.     setblend(blend_alpha)
  95.     setalpha(1)
  96.     setcolor(255,255,255)
  97.     setscale(1,1)
  98.     -- Calculate projectile rotation
  99.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  100.     -- Draw projectile
  101.     projectiles[id].frametimer=projectiles[id].frametimer+1
  102.     if projectiles[id].frametimer>5 then
  103.         projectiles[id].frametimer=0
  104.         projectiles[id].frame=1-projectiles[id].frame
  105.     end
  106.     if projectiles[id].frame==0 then
  107.         drawimage(cc.chainsawlauncher.gfx_pro0,projectiles[id].x,projectiles[id].y)
  108.     else
  109.         drawimage(cc.chainsawlauncher.gfx_pro1,projectiles[id].x,projectiles[id].y)
  110.     end
  111.     -- Draw Arrow if out of Screen
  112.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  113. end
  114.  
  115. function cc.chainsawlauncher.chainsaw.update(id)                                    -- Update
  116.     -- Move
  117.     cc.chainsawlauncher.chainsaw.move(id,1)
  118. end
  119.  
  120. function cc.chainsawlauncher.chainsaw.move(id,fx)
  121.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  122.     -- Particle Tail
  123.     if (fx==1) then
  124.         particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  125.         particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  126.         particlefadealpha(0.01)
  127.     end
  128.     -- Wind + Gravity influence on speed
  129.     projectiles[id].sx=projectiles[id].sx+getwind()*0.3
  130.     projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
  131.     -- Move (in substep loop for optimal collision precision)
  132.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/5)
  133.     msubx=projectiles[id].sx/msubt
  134.     msuby=projectiles[id].sy/msubt
  135.     for i=1,msubt,1 do
  136.         projectiles[id].x=projectiles[id].x+msubx
  137.         projectiles[id].y=projectiles[id].y+msuby
  138.         -- Collision
  139.         if collision(col5x5,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
  140.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  141.                 playsound(cc.chainsawlauncher.sfx_cut)
  142.                 -- Cause Player damage
  143.                 if playercollision()~=0 and fx==1 then
  144.                     playerdamage(playercollision(),10)
  145.                     blood(getplayerx(playercollision()),getplayery(playercollision()))
  146.                 end
  147.                 -- Cause Object damage
  148.                 if objectcollision()>0 and fx==1 then
  149.                     objectdamage(objectcollision(),10)
  150.                     projectiles[id].timer=25
  151.                 end
  152.                 -- Destroy terrain
  153.                 terrainexplosion(projectiles[id].x,projectiles[id].y,12,2)
  154.                 -- Timer / Free
  155.                 projectiles[id].timer=projectiles[id].timer+1
  156.                 if projectiles[id].timer>=25 then
  157.                     -- Explode
  158.                     arealdamage(projectiles[id].x,projectiles[id].y,30,15)
  159.                     terrainexplosion(projectiles[id].x,projectiles[id].y,20,1)
  160.                     -- Crater
  161.                     grey=math.random(0,40)
  162.                     if math.random(0,1)==1 then
  163.                         terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  164.                     else
  165.                         terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  166.                     end
  167.                     -- Free
  168.                     freeprojectile(id)
  169.                     break
  170.                 end
  171.             end
  172.         elseif (fx==1) then
  173.             projectiles[id].ignore=0
  174.         end
  175.         -- Water
  176.         if (projectiles[id].y)>getwatery()+5 then
  177.             -- Effects
  178.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  179.             playsound(sfx_hitwater1)
  180.             -- Free projectile
  181.             freeprojectile(id)
  182.             break
  183.         end
  184.     end
  185. end